Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to flush sinks on shutdown #912

Merged
merged 4 commits into from
Mar 7, 2022

Conversation

csolidum
Copy link
Contributor

@csolidum csolidum commented Mar 4, 2022

Summary

Add a new config option flush_on_shutdown which when enabled, flushes sinks as part of a graceful shutdown

Motivation

This is useful for when veneur is run as a sidecar for short lived pods like cronjobs so that we can clean up resources without having to wait for an entire flush interval. Related issue is #806

Test plan

Tested a build with this locally and observed that sinks where flushed when we hit the quitquitquit endpoint.

Rollout/monitoring/revert plan

Setting the flush_on_shutdown config option as true for veneur will enable this behavior. Removing/setting this value to false will revert this.

@csolidum csolidum changed the title Csolidum/upstream flush Add option to flush sinks on shutdown Mar 4, 2022
@arnavdugar-stripe
Copy link
Contributor

Thanks for the change, sorry I didn't get a chance to take a look today. I'll take a look on Monday.

server.go Outdated
@@ -1372,6 +1375,11 @@ func (s *Server) Shutdown() {
// TODO(aditya) shut down workers and socket readers
s.logger.Info("Shutting down server gracefully")
close(s.shutdown)
if s.FlushOnShutdown {
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(s.Interval))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is interval required? what happens if flush is set to true, but interval isn't set? could that potentially lead to not allowing enough time for flushing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like veneur has a default interval setting of 10s. My concern with not setting some sort of timeout is that the sidecar might get stuck in some sort of shutdown flow. In the case of flushing taking too long, this timeout also applies to the normal flush to sinks, so if flushing takes longer than this, you're already dropping metrics.

server.go Outdated
@@ -1372,6 +1375,11 @@ func (s *Server) Shutdown() {
// TODO(aditya) shut down workers and socket readers
s.logger.Info("Shutting down server gracefully")
close(s.shutdown)
if s.FlushOnShutdown {
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(s.Interval))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, context.WithTimeout(context.Background(), s.Interval) is one less step.

vanstee
vanstee previously approved these changes Mar 7, 2022
@arnavdugar-stripe
Copy link
Contributor

This change LGTM, happy to help merge after merging master into this branch.

@csolidum
Copy link
Contributor Author

csolidum commented Mar 7, 2022

This change LGTM, happy to help merge after merging master into this branch.

Thanks! Rebased on the current master, feel free to merge whenever.

@arnavdugar-stripe arnavdugar-stripe merged commit e6bd72f into stripe:master Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants